package com.cmccgz.udacs_landlord_webapp.data;


import com.cmccgz.udacs_landlord_webapp.base.ApiService;
import com.cmccgz.udacs_landlord_webapp.bean.PushRequestBean;
import com.cmccgz.udacs_landlord_webapp.bean.ResultBean;

import java.util.ArrayList;
import java.util.List;

import rx.Subscriber;

public class PushRequestRepository implements PushRequestListDataSource {
    @Override
    public void getRequestList(String q_word, String o_cond, String page, final PushRequestListLisenter callBack) {
        if (callBack==null) {
            return;
        }
        ApiService.getRequestList(q_word,o_cond,page).subscribe(new Subscriber<ResultBean<List<PushRequestBean>>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                callBack.getReqListError("获取失败！");
            }

            @Override
            public void onNext(ResultBean<List<PushRequestBean>> listResultBean) {
                if ("0".equals(listResultBean.rsmsg.rscode)) {
                    List<PushRequestBean> datas = listResultBean.resp == null ? new ArrayList<PushRequestBean>() : listResultBean.resp;
                    callBack.getReqListSuccess(datas);
                } else {
                    callBack.getReqListError(listResultBean.rsmsg.rsdesc);
                }
            }
        });
    }
}
